import React, { FC, useEffect } from "react";
import { Form, Input } from "antd";
import { QuestionInfoType } from "./type";
const { TextArea } = Input;

const PropsComponent: FC<QuestionInfoType> = (props) => {
  const { title, placeholder, onchange, disabled } = props;
  const [form] = Form.useForm();
  useEffect(() => {
    form.setFieldsValue({ title, placeholder });
  }, [title, placeholder]);
  function handleValueChange() {
    if (onchange) {
      onchange(form.getFieldsValue());
    }
  }
  return (
    <Form initialValues={{ title, placeholder }} layout="vertical" form={form} onValuesChange={handleValueChange} disabled={disabled}>
      <Form.Item label="标题" name="title" rules={[{ required: true, message: "请输入标题!" }]}>
        <Input />
      </Form.Item>
      <Form.Item label="描述" name="placeholder">
        <TextArea rows={4} />
      </Form.Item>
    </Form>
  );
};

export default PropsComponent;
